package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.ExceptionHelper;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.BestNewHotModel;
import com.jsyh.maidu.utils.Utils;
import com.jsyh.maidu.views.HomewMoreView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/23.
 */

public class HomeMorePresenter extends BasePresenter {

    Context context;
    HomewMoreView homemore;

    public HomeMorePresenter (Context context,HomewMoreView homemore)
    {
        this.context=context;
        this.homemore=homemore;
    }

    public void loadHomeMore(int page)
    {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String ,String > params=new HashMap<>();
        params.put("page",page+"");

        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "first/goods_list", params, new BaseDelegate.ResultCallback<BestNewHotModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                mLoadingDialog.dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(BestNewHotModel response, Object tag) {
                mLoadingDialog.dismiss();
                homemore.getHomeMore(response);

            }
        });
    }

}
